/* 
* Filename:
* main.sqf 
*
* Description:
* Gives the currently logged in admin access to special actions: teleport (click on map), ghost (enemy will not fire on you), Spectator (ACE only)
* 
* Created by [KH]Jman
* Creation date: 15/12/2010
* Email: jman@kellys-heroes.eu
* Web: http://www.kellys-heroes.eu
* 
* modified for MSO: 16/08/2012
*
* */


// MAIN
private ["_player"];
_player = _this select 0;

if (isServer) then {
	MSO_AdminActions_EventHandler = [];
	publicVariable "MSO_AdminActions_EventHandler";
};
waituntil {!isnil "MSO_AdminActions_EventHandler"};
"MSO_AdminActions_EventHandler" addPublicVariableEventHandler {(_this select 1) call FNC_ADMINACTIONS_HANDLE_EVENT;};

// Functions common to server and client
// ====================================================================================
FNC_ADMINACTIONS_HANDLE_EVENT =
{ 
	if (debug_mso) then { diag_log Format["ADMINACTIONS_EVENT: %1",_this]; };
	_event_name = _this select 0;
	_event_params = _this select 1;
	switch (tolower(_event_name)) do {
		case "punishment_jail": {
			_event_params call FNC_PUNISHMENT_JAIL;
		};
		case "punishment_unjail": {
			_event_params call FNC_PUNISHMENT_UNJAIL;
		};
		case "punishment_kick": {
			_event_params call FNC_PUNISHMENT_KICK;
		};
		case "punishment_ban": {
			_event_params call FNC_PUNISHMENT_BAN;
		};
		case "punishment_feedback": {
			_event_params spawn FNC_PUNISHMENT_FEEDBACK;
		};
		case "punishment_server": {
			_event_params call FNC_PUNISHMENT_SERVER;
		};
		case "punishment_server_feedback": {
			_event_params spawn FNC_PUNISHMENT_SERVER_FEEDBACK;
		};
		case "punishment_broadcast": {
			_event_params spawn FNC_PUNISHMENT_BROADCAST;
		};
		case "admin_informplayer": {
			_event_params spawn FNC_INFORM_PLAYER;
		};
		case "admin_teleportplayer": {
			_event_params spawn FNC_TELEPORT_PLAYER;
		};
	};
};
// ====================================================================================
FNC_ADMINACTIONS_RAISE_EVENT =
{ 
	MSO_AdminActions_EventHandler = _this;
	publicVariable "MSO_AdminActions_EventHandler";
	_this call FNC_ADMINACTIONS_HANDLE_EVENT;
};
// ====================================================================================
FNC_PUNISHMENT_JAIL =
{ 
	if (!isServer) exitWith {};
	private ["_player","_member","_pos"];
	_player = _this select 0;
	_member = _this select 1;
	diag_log format ["MSO-%1 JAIL:%2",time,[_player,str _player, name _player, getPlayerUID _player,_member,str _member, name _member, getPlayerUID _member]];
	_player setVariable ["IS_PLAYER_JAILED",true,true];
	_pos = (getMarkerPos "MSO_PUNISHMENT");
	if ((_pos distance [0,0,0]) > 0) then {
		_player setPos _pos;
	};
	["punishment_feedback",[_member,["STR_JAILED",name _player, getPlayerUID _player]]] call FNC_ADMINACTIONS_RAISE_EVENT;	
	["punishment_broadcast",["STR_JAILED_BRC",name _player]] call FNC_ADMINACTIONS_RAISE_EVENT;	
};
// ====================================================================================
FNC_PUNISHMENT_UNJAIL =
{ 
	if (!isServer) exitWith {};
	private ["_player","_member"];
	_player = _this select 0;
	_member = _this select 1;
	diag_log format ["MSO-%1 UNJAIL:%2",time,[_player,str _player, name _player, getPlayerUID _player,_member,str _member, name _member, getPlayerUID _member]];
	_player setVariable ["IS_PLAYER_JAILED",false,true];
	_player setPos (getMarkerPos "respawn_west");
	["punishment_feedback",[_member,["STR_UNJAILED",name _player, getPlayerUID _player]]] call FNC_ADMINACTIONS_RAISE_EVENT;	
};
// ====================================================================================
FNC_PUNISHMENT_KICK =
{ 
	if (!isServer) exitWith {};
	_player = _this select 0;
	_member = _this select 1;
	serverCommand format["#kick %1",getPlayerUID _player];
	diag_log format ["MSO-%1 KICK:%2",time,[_player,str _player, name _player, getPlayerUID _player,_member,str _member, name _member, getPlayerUID _member]];
	["punishment_feedback",[_member,["STR_KICKED",name _player, getPlayerUID _player]]] call FNC_ADMINACTIONS_RAISE_EVENT;	
	["punishment_broadcast",["STR_KICKED_BRC",name _player]] call FNC_ADMINACTIONS_RAISE_EVENT;	
};
// ====================================================================================
FNC_PUNISHMENT_BAN =
{ 
	if (!isServer) exitWith {};
	_player = _this select 0;
	_member = _this select 1;
	serverCommand format["#exec ban %1",getPlayerUID _player];
	diag_log format ["MSO-%1 BAN:%2",time,[_player,str _player, name _player, getPlayerUID _player,_member,str _member, name _member, getPlayerUID _member]];
	["punishment_feedback",[_member,["STR_BANNED",name _player, getPlayerUID _player]]] call FNC_ADMINACTIONS_RAISE_EVENT;	
	["punishment_broadcast",["STR_BANNED_BRC",name _player]] call FNC_ADMINACTIONS_RAISE_EVENT;	
};
// ====================================================================================
FNC_PUNISHMENT_SERVER =
{ 
	private ["_n","_uid","_array_tk","_player","_action","_name"];
	_player = _this select 0;
	_action = _this select 1;
	_reason = _this select 2;
	_uid = getPlayerUID _player;
	_name = name _player;
	if (_action == "kick") then {
		diag_log format ["MSO-%1 KICK:%2",time,[_player,str _player, name _player, getPlayerUID _player,"Server",_reason]];
		serverCommand format["#kick %1",getPlayerUID _player];
		["punishment_server_feedback",[_player, _action, getPlayerUID _player,["STR_KICKED",name _player, getPlayerUID _player]]] call FNC_ADMINACTIONS_RAISE_EVENT;	
	} else {
		_array_tk = BTC_logic getVariable "BTC_TKs_string";
		if (_array_tk find _uid == -1) then {
			_array_tk = _array_tk + [[_uid, _name]];
		};
		BTC_logic setVariable ["BTC_TKs_string",_array_tk, true];
		diag_log format ["MSO-%1 BAN:%2",time,[_player,str _player, name _player, getPlayerUID _player,"Server",_reason]];
		["punishment_server_feedback",[_player, _action, getPlayerUID _player,["STR_BANNED",name _player, getPlayerUID _player]]] call FNC_ADMINACTIONS_RAISE_EVENT;	
		serverCommand format["#exec ban %1",getPlayerUID _player];
	};
};
// ====================================================================================
FNC_PUNISHMENT_SERVER_FEEDBACK =
{ 
	private ["_uid","_player","_message","_action"];
	_player = _this select 0;
	_action = _this select 1;
	_uid = _this select 2;
	_message = _this select 3;
	if (_action == "kick") then {
		if (player == _player || getPlayerUID player == _uid) then {
			if (typename _message == typename []) then {
				_translation = [];
				{
					_translated = localize _x;
					if (_translated == "") then { _translated = _x; };
					_translation set [count _translation, _translated];
				} foreach _message;
				_message = format _translation;
			};
			hint _message;
			titleText [localize "STR_SERVER_PUNISHED","BLACK FADED"];
			player setPos [0,0,0];
			player allowDamage false;
			removeAllWeapons player;
			{ player removeMagazine _x;
			} foreach (magazines player);
			while {true} do
			{
				player setPos [0,0,0];
				titleText [localize "STR_SERVER_PUNISHED","BLACK FADED"];
				sleep 1;
			};
		};
	} else {
		if (player == _player || getPlayerUID player == _uid) then {
			if (typename _message == typename []) then {
				_translation = [];
				{
					_translated = localize _x;
					if (_translated == "") then { _translated = _x; };
					_translation set [count _translation, _translated];
				} foreach _message;
				_message = format _translation;
			};
			hint _message;
			titleText [localize "STR_TK_PUNISHED","BLACK FADED"];
			player setPos [0,0,0];
			player allowDamage false;
			removeAllWeapons player;
			{ player removeMagazine _x;
			} foreach (magazines player);
			while {true} do
			{
				player setPos [0,0,0];
				titleText [localize "STR_TK_PUNISHED","BLACK FADED"];
				sleep 1;
			};
		};
	};
};
// ====================================================================================
FNC_TELEPORT_PLAYER =
{ 
	private ["_player","_admin","_pos","_vec"];
	_player = _this select 0;
	_admin = _this select 1;
	diag_log format ["MSO-%1 TELEPORT:%2",time,[_player,str _player, name _player, getPlayerUID _player,_admin, name _admin, getPlayerUID _admin]];
	_pos = getMarkerPos "respawn_west";
	_pos = _pos findEmptyPosition[0 , 50];
	if (count _pos <= 0) then { _pos = getMarkerPos "respawn_west"; };
	_pos set [2,0.1];
	if (vehicle _player != _player) then {
		_vec = vehicle _player;
		_player action ["eject", _vec];
		waituntil {vehicle _player == _vec};
	};
	_player setVelocity [0,0,0];
	_player setPos _pos;
	sleep 0.4;
	if ((_player distance _pos) < 1) then {
		["admin_informplayer",["STR_PLAYER_TELEPORTED",getPlayerUID _player,0,"BLACK OUT",4]] call FNC_ADMINACTIONS_RAISE_EVENT;
	};
	
};
// ====================================================================================

if (player != _player) exitWith { };

if(isNil "CFG_MarkerMode") then {CFG_MarkerMode = false;};
if(isNil "CFG_TeamMember") then {CFG_TeamMember = false;};
if(isNil "CFG_TeamRecruit") then {CFG_TeamRecruit = false;};
if(isNil "CFG_TeamModerator") then {CFG_TeamModerator = false;};
if(isNil "CFG_TeamAdmin") then {CFG_TeamAdmin = false;};
if(isNil "CFG_AdminCmds") then {CFG_AdminCmds = 1;};
if(isNil "CFG_AdminCmdTeleport") then {CFG_AdminCmdTeleport = 1;};
if(isNil "CFG_AdminCmdGhost") then {CFG_AdminCmdGhost = 1;};
if(isNil "CFG_AdminCmdSpectator") then {
	if(isClass(configFile>>"CfgPatches">>"ace_main")) then {
		CFG_AdminCmdSpectator = 1;
	} else {
		CFG_AdminCmdSpectator = 0;
	};
};
if (CFG_AdminCmds == 0) exitwith {diag_log format ["MSO-%1 Adminactions turned off - Exiting.",time];};
diag_log format ["MSO-%1 Adminactions turned on",time];
"Admin Actions" call mso_core_fnc_initStat;

// ====================================================================================
FNC_GHOST_CODE =
{ 
	private ["_player"];
	_player = _this select 0;
	if (player != _player) exitWith { }; 
	if (FNC_GHOST_ACTION == -1)then {
		FNC_GHOST_ACTION = player addAction [localize "STR_GHOST_MODE", "base\core\modules\adminActions\ghostmode.sqf",[],-10,false,true];
		if (debug_mso) then { diag_log format ["MSO-%1 FNC_GHOST_CODE: %2",time,FNC_GHOST_ACTION]; };
	};
};
// ====================================================================================
FNC_TELEPORT_CODE =
{
	private ["_player"];
	_player = _this select 0;
	if (player != _player) exitWith { };
	if (FNC_TELEPORT_ACTION == -1)then { 
		FNC_TELEPORT_ACTION = player addAction [localize "STR_TELEPORT_MODE", "base\core\modules\adminActions\teleportmode.sqf",[],-10,false,true];
		if (debug_mso) then { diag_log format ["MSO-%1 FNC_TELEPORT_CODE: %2",time,FNC_TELEPORT_ACTION]; };
	};
};
// ====================================================================================
FNC_SPECTATOR_CODE =
{ 
	private ["_player"];
	_player = _this select 0;
	if (player != _player) exitWith { };
	if (FNC_SPECTATOR_ACTION == -1)then {
		FNC_SPECTATOR_ACTION = player addAction [localize "STR_SPECTATOR_MODE", "base\core\modules\adminActions\spectatormode.sqf",[],-10,false,true];
		if (debug_mso) then { diag_log format ["MSO-%1 FNC_SPECTATOR_CODE: %2",time,FNC_SPECTATOR_ACTION]; };
	};
};
// ====================================================================================
FNC_MARKER_CODE =
{ 
	private ["_player"];
	_player = _this select 0;
	if (player != _player) exitWith { };
	if (FNC_MARKER_ACTION == -1)then {
		FNC_MARKER_ACTION = player addAction [localize "STR_MARKER_MODE", "base\core\modules\adminActions\markermode.sqf",[],-10,false,true];
		if (debug_mso) then { diag_log format ["MSO-%1 FNC_MARKER_CODE: %2",time,FNC_MARKER_ACTION]; };
	};
};
// ====================================================================================
FNC_PUNISHMENT_CODE =
{ 
	private ["_player"];
	_player = _this select 0;
	if (player != _player) exitWith { };
	if (FNC_PUNISHMENT_ACTION == -1)then {
		FNC_PUNISHMENT_ACTION = player addAction [localize "STR_PUNISHMENT", "base\core\modules\adminActions\punishment.sqf",[],-10,false,true];
		if (debug_mso) then { diag_log format ["MSO-%1 FNC_PUNISHMENT_CODE: %2",time,FNC_PUNISHMENT_ACTION]; };
	};
};
// ====================================================================================
FNC_TELEPORTBASE_CODE =
{ 
	private ["_player"];
	_player = _this select 0;
	if (player != _player) exitWith { };
	if (FNC_TELEPORTBASE_ACTION == -1)then {
		FNC_TELEPORTBASE_ACTION = player addAction [localize "STR_TELEPORT_TO_BASE", "base\core\modules\adminActions\teleportbase.sqf",[],-10,false,true];
		if (debug_mso) then { diag_log format ["MSO-%1 FNC_TELEPORTBASE_CODE: %2",time,FNC_TELEPORTBASE_ACTION]; };
	};
};
// ====================================================================================
FNC_PUNISHMENT_PLAYER_EXEC =
{ 
	private ["_trg","_punished","_end_jail"];
	if (debug_mso) then { diag_log format ["MSO-%1 PUNISHMENT_EXEC:%2",time,[_this,list (_this select 0),(({getPlayerUID _x == getPlayerUID player}count (list (_this select 0))) > 0),player getVariable "IS_PLAYER_JAILED"]]; };
	if (!(player getVariable "IS_PLAYER_JAILED")) exitWith {if (debug_mso) then { diag_log format ["MSO-%1 PUNISHMENT_EXEC:%2",time,"Not Jailed"];};};
	_trg = _this select 0;
	_punished = player getVariable "IS_PLAYER_PUNISHED";
	if (isnil "_punished") then {_punished = false};
	if (_punished && debug_mso) exitWith {diag_log format ["MSO-%1 PUNISHMENT_EXEC:%2",time,"Already Being Punished"];};
	player setVariable ["IS_PLAYER_PUNISHED", true];
	_end_jail = time + 60;
	disableUserInput true;
	while { ({getPlayerUID _x == getPlayerUID player}count (list _trg)) > 0 && (player getVariable "IS_PLAYER_JAILED") && time < _end_jail} do {
		_punished = true;
		titleText [Format[localize "STR_PUNISHED",floor(_end_jail - time)], "BLACK FADED"];
		sleep 1;
	};
	disableUserInput false;
	player setVariable ["IS_PLAYER_PUNISHED", false];
	if (_punished) then {
		player setPos (getMarkerPos "respawn_west");
		titleText [localize "STR_RELEASED", "PLAIN",3];
		titleFadeOut 3;
	};
};
// ====================================================================================
FNC_PUNISHMENT_FEEDBACK =
{ 
	if (isDedicated) exitWith {};
	_player = _this select 0;
	_message = _this select 1;
	if (_player != player) exitWith {};
	if (debug_mso) then { diag_log format ["MSO-%1 FEEDBACK:%2",time,[_player,str _player, name _player,_message]]; };
	if (typename _message == typename []) then {
		_translation = [];
		{
			_translated = localize _x;
			if (_translated == "") then { _translated = _x; };
			_translation set [count _translation, _translated];
		} foreach _message;
		_message = format _translation;
	};
	hint _message;
};
// ====================================================================================
FNC_PUNISHMENT_BROADCAST =
{ 
	private ["_message","_translation","_translated"];
	_message = _this;
	if (isDedicated) exitWith {};
	if (typename _message == typename []) then {
		_translation = [];
		{
			_translated = localize _x;
			if (_translated == "") then { _translated = _x; };
			_translation set [count _translation, _translated];
		} foreach _message;
		_message = format _translation;
	};
	BTC_Logic globalChat _message;
};
// ====================================================================================
FNC_MARKER_DISPLAY =
{ 
	private ["_allUnits","_markers","_units","_unit","_marker","_i","_veh","_x","_name","_vecs","_marker_type","_pos"];
	_markers = [];
	_units = [];
	_vecs = [];
	_vecs_markers = [];
	while {true} do {
		if (CFG_MarkerMode) then {
			{
				_veh = _x;
				_name = vehicleVarName _veh;
				if (_name != "" && !(_veh in BTC_vehs_mobile_west) && !(_veh in BTC_vehs_mobile_east) && (_veh isKindOf "AllVehicles")) then {
					// diag_log format["%1, %2, %3",typeof _veh, _veh, _name];
					_marker = format["mrk_%1",_name];
					if (!(_veh in _vecs)) then {
						createMarkerLocal [_marker, getPos _veh];
						_marker setMarkerColorLocal "ColorGreen";
						_marker setMarkerShapeLocal "ICON";
						_marker_type = "mil_box";
						if (_veh isKindOf "Car") then {	_marker_type = "n_mech_inf"; };
						if (_veh isKindOf "Tank") then { _marker_type = "n_armor"; };
						if (_veh isKindOf "Air") then { _marker_type = "n_air"; };
						if (_veh isKindOf "Ship") then { _marker_type = "c_ship"; };
						if (_veh isKindOf "Quadbike_Base_F") then { _marker_type = "n_inf"; };
						if (_veh isKindOf "Offroad_Base") then { _marker_type = "c_car"; };
						_marker setMarkerTypeLocal _marker_type;
						_marker setMarkerSizeLocal [0.7,0.7];
						_marker setMarkerAlphaLocal 0.6;
						_marker setMarkerTextLocal _name;
						_vecs_markers set [count _vecs_markers, _marker];
						_vecs set [count _vecs, _veh];
					};
				};
			} foreach vehicles;
			for [{_i = 0},{_i < count _vecs},{_i = _i + 1}] do {
				_veh = _vecs select _i;
				_marker = _vecs_markers select _i;
				if (alive _veh) then {
					_marker setMarkerPosLocal (getPos _veh);
					_marker setMarkerAlphaLocal 0.5;
				} else {
					_vecs_markers set [_i, "XxDeLxX"];
					_vecs set [_i, "XxDeLxX"];
					_marker setMarkerPosLocal [0,0,0];
					_marker setMarkerAlphaLocal 0;
					deleteMarker _marker;
				};
			};
			_vecs = _vecs - ["XxDeLxX"];
			_vecs_markers = _vecs_markers - ["XxDeLxX"];

			_allUnits = switchableUnits;
			if (isMultiplayer) then { _allUnits = playableUnits;};
			{
				_unit = _x;
				if (!(_unit in _units)) then {
					_units set[count _units, _unit];
					_marker = format["player_unit_marker_%1",count _markers];
					_markers set[count _markers, _marker];
					createMarkerLocal [_marker,[0,0,0]];
					_marker setMarkerAlphaLocal 0;
					_marker setMarkerShapeLocal "ICON";
					_marker setMarkerTypeLocal "mil_dot";
					_marker setMarkerColorLocal "ColorBlue";
					_marker setMarkerTextLocal (name _unit);
				};
			} foreach _allUnits;
			for [{_i = 0},{_i < count _markers},{_i = _i + 1}] do {
				_unit = _units select _i;
				_marker = _markers select _i;
				if (alive _unit) then {
					_marker setMarkerAlphaLocal 0.5;
					_pos = (getPos (vehicle _unit));
					_marker setMarkerTextLocal Format["%1",(name _unit),getPlayerUID _unit];
					// _marker setMarkerTextLocal Format["%1 (%2)",(name _unit),getPlayerUID _unit];
					if (vehicle _unit != _unit) then {
						_marker setMarkerColorLocal "ColorGreen";
						if ((driver (vehicle _unit)) == _unit) then {
							_marker setMarkerColorLocal "ColorKhaki";
						};
						_pos set [1, (_pos select 1) - (((crew (vehicle _unit)) find _unit) * 1.5) - 1.5];
					} else {
						_marker setMarkerColorLocal "ColorBlue";
					};
					_marker setMarkerPosLocal _pos;
				} else {
					_marker setMarkerPosLocal [0,0,0];
					_marker setMarkerAlphaLocal 0;
				};
			};
		} else {
			{
				_x setMarkerPosLocal [0,0,0];
				_x setMarkerAlphaLocal 0;
			} foreach _markers;
			{
				_x setMarkerPosLocal [0,0,0];
				_x setMarkerAlphaLocal 0;
			} foreach _vecs_markers;
		};
		sleep 1.7654;
	};
};
// ====================================================================================
FNC_PLAYER_RESPAWN = {
	private ["_isAdmin","_player"];
	_player = _this select 0;
	if (player != _player) exitWith { }; 
	diag_log format ["MSO-%1 FNC_PLAYER_RESPAWN: started",time];
	FNC_GHOST_ACTION = -1;
	FNC_TELEPORT_ACTION = -1;
	FNC_SPECTATOR_ACTION = -1;
	FNC_Vehicle_Action = -1;
	FNC_PUNISHMENT_ACTION = -1;
	FNC_MARKER_ACTION = -1;
	FNC_TELEPORTBASE_ACTION = -1;
	
	if (CFG_AdminCmds == 1) then { 
		[_player] spawn {
			private ["_end","_isAdmin"];
			teleportMode = false;
			_end = false;
			waitUntil { 
				_isAdmin = serverCommandAvailable "#kick" || !isMultiplayer;

				if (_isAdmin || CFG_TeamAdmin) then {
					if (CFG_AdminCmdGhost == 1) then { [player] call FNC_GHOST_CODE; };
					if (CFG_AdminCmdTeleport == 1) then { [player] call FNC_TELEPORT_CODE; };
					if (isClass(configFile>>"CfgPatches">>"ace_main") && CFG_AdminCmdSpectator == 1) then { [player] call FNC_SPECTATOR_CODE; };
				} else {
					if ((FNC_GHOST_ACTION != -1) || (FNC_TELEPORT_ACTION != -1) || (FNC_SPECTATOR_ACTION != -1)) then {
						if (CFG_AdminCmdGhost == 1) then { player removeAction FNC_GHOST_ACTION;};
						if (CFG_AdminCmdTeleport == 1) then { player removeAction FNC_TELEPORT_ACTION; };
						if (isClass(configFile>>"CfgPatches">>"ace_main") && CFG_AdminCmdSpectator == 1) then { player removeAction FNC_SPECTATOR_ACTION;};
						_end = true;
					};				
				};
				if (_isAdmin || CFG_TeamAdmin || CFG_TeamModerator) then {
					[player] call FNC_PUNISHMENT_CODE;
				} else {
					if ((FNC_PUNISHMENT_ACTION != -1)) then {
						player removeAction FNC_PUNISHMENT_ACTION;
						_end = true;
					};
				};
				if (_isAdmin || CFG_TeamAdmin || CFG_TeamMember) then {
					[player] call FNC_MARKER_CODE;
					[player] call FNC_TELEPORTBASE_CODE;
				} else {
					if ((FNC_MARKER_ACTION != -1) || (FNC_TELEPORTBASE_ACTION != -1)) then {
						player removeAction FNC_MARKER_ACTION;
						player removeAction FNC_TELEPORTBASE_ACTION;
						_end = true;
					};
				};
				if (_end) then {
					_this call FNC_PLAYER_RESPAWN;
				};
				sleep 3;
				(gameOver || _end);
			};
			if (debug_mso) then { diag_log format ["MSO-%1 FNC_PLAYER_RESPAWN: ended",time]; };
		};
	};
};	
// ====================================================================================
FNC_INFORM_PLAYER =
{ 
	private ["_player","_text","_tmp","_is_target","_duration","_type","_fadeout"];
	_player = "";
	_is_target = true;
	_duration = 20;
	_type = "PLAIN";
	_fadeout = 0;
	_text = "SERVER RESTART\n\nThe Server will soon Restart for maintenance.\n\n\nREDÉMARRAGE SERVEUR\n\nLe serveur va redémarrer pour une maintenance.";
	if (typename _this == typename []) then {
		if (count _this > 0) then { _text = _this select 0 };
		if (count _this > 1) then { _player = _this select 1 };
		if (count _this > 2) then { _duration = _this select 2 };
		if (count _this > 3) then { _type = _this select 3 };
		if (count _this > 4) then { _fadeout = _this select 4 };
	};
	if (_player != "") then {
		_is_target = (_player == str (player) || _player == name(player) || _player == getPlayerUID(player));
	};
	if (_text != "") then {
		_tmp = localize _text;
		if (_tmp != "") then { _text = _tmp };
	};
	if (!isDedicated && _is_target) then {
		titleText [_text,_type,_duration];
		if (_fadeout > 0) then {
			titleFadeOut _fadeout;
		};
	};
};
// ====================================================================================

if (CFG_AdminCmds == 1) then {
	gameOver = false;
	player addeventhandler ["Respawn", { _this call FNC_PLAYER_RESPAWN; } ];
	_this spawn {
		waituntil {!isnil "MSO_R_Member" || !alive player};
		if (alive player) then {
			CFG_TeamMember = (getPlayerUID player) in MSO_R_Member;
			CFG_TeamRecruit = (getPlayerUID player) in MSO_R_Recruit;
			CFG_TeamAdmin = (getPlayerUID player) in MSO_R_Admin;
			CFG_TeamModerator = (getPlayerUID player) in MSO_R_Moderator;
			_this call FNC_PLAYER_RESPAWN;
		} else {
			waituntil {!isnil MSO_R_Member};
			CFG_TeamMember = (getPlayerUID player) in MSO_R_Member;
			CFG_TeamRecruit = (getPlayerUID player) in MSO_R_Recruit;
			CFG_TeamAdmin = (getPlayerUID player) in MSO_R_Admin;
			CFG_TeamModerator = (getPlayerUID player) in MSO_R_Moderator;
		};
		if (debug_mso) then { diag_log format ["MSO-%1 AdminActions:%2",time,[name player,CFG_TeamAdmin,CFG_TeamMember]]; };
		if (CFG_TeamMember || CFG_TeamAdmin || !isMultiplayer) then {
			[] spawn FNC_MARKER_DISPLAY;
		};
	};
};
// ====================================================================================
